/*
 * Copyright 2011 Raimon Rodriguez
 * 
 * This file is part of sgfx.
 * 
 * sgfx is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * sgfx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with sgfx. If not, see <http://www.gnu.org/licenses/>.
 */

package com.googlecode.sgfx.base;

import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

/**
 *
 * @author raimon.rodriguez
 */
public class EmptyListModelFrame extends JFrame {

    public EmptyListModelFrame() {
        initComponents();
        jList1.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
        emptyModelButton.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    }


    public static void main(String... pArgs) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new EmptyListModelFrame().setVisible(true);
            }
        });
    }
    

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new JScrollPane();
        jList1 = new JList();
        emptyModelButton = new JButton();

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        jList1.setModel(new AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        emptyModelButton.setText("empty model");
        emptyModelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                emptyModelButtonActionPerformed(evt);
            }
        });

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(GroupLayout.LEADING)
                    .add(jScrollPane1, GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
                    .add(emptyModelButton))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(LayoutStyle.UNRELATED)
                .add(emptyModelButton)
                .addContainerGap(86, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void emptyModelButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_emptyModelButtonActionPerformed
        jList1.setModel(ListModels.emptyListModel());
    }//GEN-LAST:event_emptyModelButtonActionPerformed
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JButton emptyModelButton;
    private JList jList1;
    private JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
